package com.jason.www.controller;

import com.jason.www.domain.User;
import com.jason.www.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * Created by Cai on 2018/6/9.
 */
@Controller
@RequestMapping("/text")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("/text")
    public String userTest(ModelMap modelMap){
        modelMap.put("hello","hello world");
        return "text";
    }

    @RequestMapping("/txTest")
    public ModelAndView transationTest(){
        ModelAndView modelAndView = new ModelAndView();
        User user = new User("xiaohong",33,"女",new Date());
        Boolean result = userService.addUser(user);
        modelAndView.getModel().put("hello",result);
        modelAndView.setViewName("text");
        return modelAndView;
    }

    @RequestMapping(value="/testJsonReq",method = RequestMethod.POST)
    @ResponseBody
    public User jsonTest(@RequestBody User user){
        System.out.println(user);
        return user;
    }

}
